﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OF.Component.Base;
using OF.Component.BLL;
using OF.Component.DTO;
using OF.Component.Model;
using OF.Utility;

namespace OP.logs
{
    public partial class logaction : OpBasePage
    {
        protected int intCount = 0;
        protected int intPageIndex = 1;
        protected string style = "";
        /// <summary>
        /// 页面脚本字符串
        /// </summary>
        protected string strMessage = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            SetPageCode(101, 10105);
            if (!IsPostBack)
            {
                BindData();
                MyBind();
            }
            if (IsSessionPostBack)
            {
                MyBind();
            }
        }
        protected void BindData()
        {
            //获取所有日志平台
            var list = LogPlatformOperate.QueryList(m => true);
            DataBindHelper.SetDropDownDataSource(drpPlatform, list, "Name", "PlatformID");


        }
        void MyBind()
        {
            var pageIndex = pager1.CurrentPageIndex;
            //获取搜索条件
            var condition=new scLogAction();

            condition.PlatformID = EConvert.ToInt(drpPlatform.SelectedValue);
            condition.StartDate = txtStartDate.Text;
            condition.EndDate = txtEndDate.Text;

            condition.PageIndex = pageIndex;
            condition.PageSize = pager1.PageSize;

            var list = LogActionOperate.SearchList(condition);
            //删除后当前分页没有数据的情况，则页数-1再次获取数据
            if (list.Count == 0 && pageIndex > 1)
            {
                condition.PageIndex--;
                list = LogActionOperate.SearchList(condition); 
            }
            rptDataList.DataSource = list;
            rptDataList.DataBind();

            if (condition.TotalRecord > 0)
            {
                style = "style=\"display:none\"";
            }
            pager1.RecordCount = condition.TotalRecord;

        }
        

      
        /// <summary>
        /// 搜索事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            pager1.CurrentPageIndex = 1;
            MyBind();
        }
        #region 翻页事件
        /// <summary>
        /// 翻页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void pager1_PageChanged(object sender, EventArgs e)
        {
            MyBind();
        }
        #endregion
    }
}